func rob(nums []int) int {
    if len(nums) == 1 {return nums[0]}
    if len(nums) == 2 {return max(nums[0], nums[1])}
    return max(RangeMax(nums, 0, len(nums)-2), RangeMax(nums, 1, len(nums)-1))
}

func RangeMax(nums []int, start, end int) int {
    dp := make([]int, end-start+1)
    dp[0] = nums[start]
    dp[1] = max(nums[start], nums[start+1])
    for i:=2; i<=end-start; i++ {
        dp[i] = max(dp[i-2]+nums[start+i], dp[i-1])
    }
    return dp[end-start]
}

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}